package com.kwq.designPattern.construct.flyweight;

import java.util.HashMap;
import java.util.Map;

/**
 * @author kangwanqiang
 * @date 2021/2/7
 * @description 汽车工厂，负责管理汽车对象
 */
public class CarFactory {
    /**
     * 管理汽车的Map
     */
    private static final Map<Integer, Car> circleMap = new HashMap<>();

    public static Car getCar(Integer color) {
        Car evCar = (Car) circleMap.get(color);

        if (evCar == null) {
            evCar = new EVCar(color);
            circleMap.put(color, evCar);
            System.out.println("Creating car of color : " + color);
        }
        return evCar;
    }
}
